$(function(){
	showPrice();
})

//选择广告位时加载对应的单价
function showPrice() {
	$("#positionprice").html(
		$('#position_id option:selected').attr("data_price"));
	updateDayAndMoney();
}

//时间控件的回调函数
function selectdate(){
	updateDayAndMoney();
}

// 更新投放天数金额等
function updateDayAndMoney() {
	var positionprice = $("#positionprice").html();
	var start_time = $("#start_time").val();
	var end_time = $("#end_time").val();
	var days = parseInt(getDays(start_time, end_time)) + 1;
	var moneysum = days * parseFloat(positionprice)
	$("#daynum").html(days);
	if (!isNaN(moneysum)) {
		$("#total_amount").val(moneysum);
	}

}

// 2时间相差的天数
function getDays(strDateStart, strDateEnd) {
	var strDateS = new Date(strDateStart.replace(/-/g, "/"));
	var strDateE = new Date(strDateEnd.replace(/-/g, "/"));
	var iDays = parseInt(Math.abs(strDateS - strDateE) / 1000 / 60 / 60 / 24)// 把相差的毫秒数转换为天数
	return iDays;
}